package ModelLayer;


/**
 * A class to represent a Customer
 * 
 * @author Mike M. Madsen, Rasmus A. Borup 
 * @version 15/12-2013
 */
public class Customer
{
    // instance variables
    private static String customerNO = "000000";
    private String id;
    private String name;
    private String email;
    private String address;
    private String phoneNO;
    private String zipCode;
    private String city;

    /**
     * Constructor for objects of class Customer without parameters for easy testing
     */
    public Customer()
    {
        nextID();
        name = "Rasmus";
        email = "Rasmus@UCN.dk";
        address = "Myrdalstræde";
        phoneNO = "01234567";
        zipCode = "9220";
        city = "Aalborg";
    }

    /**
     * Constructor for objects of class Customer
     */
    public Customer(String name, String email, String address, String phoneNO, String zipCode, String city)
    {
        nextID();
        this.name = name;
        this.email = email;
        this.address = address;
        this.phoneNO = phoneNO;
        this.zipCode = zipCode;
        this.city = city;
    }
    
    /**
     * Counts the id string up one by parsing it to int, adding one, parsing it back to String
     * and using zeroString() to add the zeroes to the start of the string
     */
    protected void nextID()
    {
        int intID = Integer.parseInt(customerNO);
        intID++;
        customerNO = zeroString() + Integer.toString(intID);
        id = customerNO;
    }
    
    /**
     * Returns number of zeroes in the start of the id String
     */
    protected int countZeroes()
    {
        int i = 0;
        boolean done = false;
        int noOfZeroes = 0;
        while(!done && i < 5)
        {
            if(customerNO.charAt(i) == '0')
            {
                noOfZeroes++;
                i++;
            }
            else
            {
                done = true;
            }
        }
        return noOfZeroes;
    }
    
    /**
     * Returns a string containing the amount of zeroes in the start of the id String using countZeroes()
     */
    protected String zeroString()
    {
        String zeroString = "";
        for(int i = 0; i < countZeroes(); i++)
        {
            zeroString += "0";
        }
        return zeroString;
    }
    
    /**
     * Returns a string containing details about a customer
     */
    public String detailsString()
    {
        String details = "Customer details: \n ID: " + id + "\n Name: " + name + "\n Email: " + email + "\n Address: " + address + "\n Phonenumber; " + phoneNO + "\n Zip code: " + zipCode + "\n City: " + city;
        return details;
    }
    
    
    //Accessors and mutators
    public String getID()
    {
        return id;
    }
        
    public String getName()
    {
        return name;
    }
    
    public void setNam(String name)
    {
        this.name = name;
    }
        
    public String getEmail()
    {
        return email;
    }
    
    public void setEmail(String email)
    {
        this.email = email;
    }
        
    public String getAddress()
    {
        return address;
    }
    
    public void setAddress(String address)
    {
        this.address = address;
    }
        
    public String getPhoneNO()
    {
        return phoneNO;
    }
    
    public void setPhoneNO(String phoneNO)
    {
        this.phoneNO = phoneNO;
    }
        
    public String getZipCode()
    {
        return zipCode;
    }
    
    public void setZipCode(String zipCode)
    {
        this.zipCode = zipCode;
    }
        
    public String getCity()
    {
        return city;
    }
    
    public void setCity(String city)
    {
        this.city = city;
    }
}
